package tq.com.tqstudent.net.ok;

import android.text.TextUtils;

import com.lzy.okgo.callback.AbsCallback;
import com.lzy.okgo.convert.StringConvert;
import com.lzy.okgo.request.base.Request;

import okhttp3.Response;
import tq.com.tqstudent.bean.UserInfo;

/**
 * @Author rames
 * @date 2019/3/8 14:32
 */
public abstract class StringCallback extends AbsCallback<String> {

    private StringConvert convert;

    public StringCallback() {
        convert = new StringConvert();
    }

    @Override
    public void onStart(Request<String, ? extends Request> request) {
        super.onStart(request);

        if(!TextUtils.isEmpty(UserInfo.getToken().trim())) {
            request.headers("X-Auth-Token", UserInfo.getToken());//
//                .params("params1", "ParamsValue1")//
//                .params("token", "3215sdf13ad1f65asd4f3ads1f");
        }
    }

    @Override
    public String convertResponse(Response response) throws Throwable {
        String s = convert.convertResponse(response);
        response.close();
        return s;
    }
}
